package com.itheima.controller;

import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.CheckItem;

import com.itheima.service.CheckItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkitem")
@Slf4j
public class CheckItemController {
    @Autowired
    private CheckItemService checkItemService;
    /*新增检查项*/
    @PostMapping("/add")
    public Result add(@RequestBody CheckItem checkItem){
        log.info("新增检查项：{}", checkItem);
        checkItemService.add(checkItem);
        return new Result(true,"添加成功",null);
    }
    /*根据id删除检查项*/
    @GetMapping("/delete")
    public Result delete(Long id){
        log.info("删除检查项id：{}", id);
        checkItemService.delete(id);
        return new Result(true,"删除成功",null);
    }
    /*根据id查询检查项*/
    @GetMapping("/findById")
    public Result findById(Long id){
        CheckItem checkItem=checkItemService.findById(id);
        return new Result(true,"查询成功",checkItem);
    }
    /*分页查询*/
    @PostMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        log.info("分页查询：{}", queryPageBean);
        PageResult pageResult = checkItemService.findPage(queryPageBean);
        return pageResult;
    }
    /*修改检查项*/
    @PostMapping("/edit")
    public Result edit(@RequestBody CheckItem checkItem){
        log.info("修改检查项：{}", checkItem);
        checkItemService.edit(checkItem);
        return new Result(true,"编辑成功",null);
    }
    /*查询所有检查项*/
    @GetMapping("/findAll")
    public List<CheckItem> findAll(){
        return checkItemService.findAll();
    }
    /*根据检查组id查询关联的检查项id*/
    @GetMapping("/findCheckItemIdsByCheckGroupId")
    public Result findCheckItemIdsByCheckGroupId(Long checkgroupId){
        List<String> list=checkItemService.findCheckItemIdsByCheckGroupId(checkgroupId);
        return new Result(true,"查询检查项成功",list);
    }
}
